/*
* @Author: steven.wang
* @Date:   2019-01-07 17:29:27
* @Last Modified by:   steven.wang
* @Last Modified time: 2019-03-04 10:31:56
*/
const db = require('./db');

/**
 * 注册用户
 * @author steven.wang
 * @DateTime 2019-02-26T16:23:11+0800
 * @param    {String}                 value 用户名
 * @return   {Promise}
 */
module.exports.addUser = values => {
	const dbSql = db.generateSql({
		action: 'add',
		table: 'user'
	});
    return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 删除用户
 * @author steven.wang
 * @DateTime 2019-02-26T16:26:48+0800
 * @param    {Number}                 id 用户ID
 * @return   {Promise}
 */
module.exports.deleteUserById = id => {
	return db.query('select * from user where id = ?', [id]);
}

/**
 * 更新用户信息
 * @author steven.wang
 * @DateTime 2019-02-26T16:26:48+0800
 * @param    {Number}                 id 用户ID
 * @return   {Promise}
 */
module.exports.updateUserById = id => {
	return db.query('select * from user where id = ?', [id]);
}

/**
 * 根据ID查找用户
 * @author steven.wang
 * @DateTime 2019-02-26T16:26:48+0800
 * @param    {Number}                 id 用户ID
 * @return   {Promise}
 */
module.exports.findUserById = id => {
	const dbSql = db.generateSql({
		wants: '*',
		action: 'search',
		table: 'user',
		conditions: {
			id: values.id
		}
	});
    return db.query(dbSql.sql, dbSql.sqlData);
}

/**
 * 根据username查询用户
 * @author steven.wang
 * @DateTime 2019-03-04T10:06:15+0800
 */
module.exports.findUserByUsername = values => {
	const dbSql = db.generateSql({
		wants: '*',
		action: 'search',
		table: 'user',
		conditions: {
			username: values.username
		}
	});
    return db.query(dbSql.sql, dbSql.sqlData);
}

